day-21

library(dataRetrieval)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tsibble)
Registered S3 method overwritten by 'tsibble':
  method               from 
  as_tibble.grouped_df dplyr

Attaching package: 'tsibble'
The following objects are masked from 'package:base':

    intersect, setdiff, union
poudre_flow <- readNWISdv(siteNumber = "06752260",    
                          parameterCd = "00060",      
                          startDate = "2013-01-01",   
                          endDate = "2023-12-31") |>  
  renameNWISColumns() |>                              
  mutate(Date = yearmonth(Date)) |>                 
  group_by(Date) |>                                   
  summarise(Flow = mean(Flow))        
GET:https://waterservices.usgs.gov/nwis/dv/?site=06752260&format=waterml%2C1.1&ParameterCd=00060&StatCd=00003&startDT=2013-01-01&endDT=2023-12-31
poudre <- poudre_flow %>% as_tsibble()
Using `Date` as index variable.
library(ggplot2)
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
poudre_plot <- ggplot(poudre, aes(x = Date, y = Flow)) +
  geom_line(color = "darkblue") +
  labs(title = "Cache la Poudre River Monthly Streamflow",
       x = "Date", y = "Mean Monthly Flow (cfs)") +
  theme_minimal()
ggplotly(poudre_plot)
library(feasts)
Loading required package: fabletools
gg_subseries(poudre, Flow) +
  labs(title = "Subseries Plot of Monthly Streamflow in the Poudre",
       y = "Streamflow (cfs)") +
  theme_minimal()

From this plot, I see that streamflow typically peaks in early summer (May-June), indicating this is likely reliant on snow melt. Low flows typically occur around December-January, which makes sense in a snowmelt stream as no snow has yet melted during winter months. In this plot, seasons are defined as months per year, and I think the subseries in this plot are the mean stream flow values for each month across all years 2013-2023.

library(fable)
decomp <- poudre |> 
  model(STL(Flow ~ season(window = "periodic"))) |> 
  components()
autoplot(decomp)